package com.example.airobotsettings.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Util {
    public static String md5(String input){
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] messageDigest = md.digest(input.getBytes());
            StringBuilder builder = new StringBuilder();
            for (byte b : messageDigest){
                String hex = Integer.toHexString(0xFF & b);
                if (hex.length() == 1) builder.append('0');
                builder.append(hex);
            }
            return builder.toString();
        } catch (Exception e) {
            throw new RuntimeException("加密失败",e);
        }
    }
}
